package kr.pe.johnkim.chattingday.mobile.rest.dao;

import kr.pe.johnkim.chattingday.mobile.domain.ChattingDayPrivateMessageWarning;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

/**
 * @author : johnkim <cale9797@gmail.com / Bettersoft Inc,.>
 * @Date : 12. 6. 12
 */
public class ChattingDayPrivateMessageWarningDaoImpl extends SqlMapClientDaoSupport implements ChattingDayPrivateMessageWarningDao {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(ChattingDayPrivateMessageWarningDaoImpl.class);
    
    /**
     * 불량 쪽지에 경고를 추가 한다.
     *
     * @param chattingDayPrivateMessageWarning
     *
     * @return
     */
    @Override
    public boolean registerPrivateMessageWarning(ChattingDayPrivateMessageWarning chattingDayPrivateMessageWarning) {
        logger.info("registerPrivateMessageWarning");

        boolean result;

        try {
            getSqlMapClientTemplate().insert("CHATTINGDAY_PRIVATE_MESSAGE_WARNING.registerPrivateMessageWarning", chattingDayPrivateMessageWarning);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 불량 쪽지에 경고를 추가한 것을 비활성화 한다.
     *
     * @param chattingDayPrivateMessageWarning
     *
     * @return
     */
    @Override
    public boolean updateDeactivatePrivateMessageWarning(ChattingDayPrivateMessageWarning chattingDayPrivateMessageWarning) {
        logger.info("updateDeactivatePrivateMessageWarning");

        boolean result;

        try {
            getSqlMapClientTemplate().update("CHATTINGDAY_PRIVATE_MESSAGE_WARNING.updateDeactivatePrivateMessageWarning", chattingDayPrivateMessageWarning);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 해당 쪽지의 불량 경고 총 갯수를 가져 온다.
     *
     * @param chattingDayPrivateMessageWarning
     *
     * @return
     */
    @Override
    public ChattingDayPrivateMessageWarning selectPrivateMessageWarningCount(ChattingDayPrivateMessageWarning chattingDayPrivateMessageWarning) {
        logger.info("selectPrivateMessageWarningCount");

        return (ChattingDayPrivateMessageWarning)getSqlMapClientTemplate().queryForObject("CHATTINGDAY_PRIVATE_MESSAGE_WARNING.selectPrivateMessageWarningCount", chattingDayPrivateMessageWarning);
    }
}
